part of '../repository.dart';

const _kWebPaymentFailureCardExpiredValue = 'card_expired';
const _kWebPaymentFailureCardUnavailableValue = 'card_unavailable';

class _WebPaymentMethodFailureDto extends Equatable {
  const _WebPaymentMethodFailureDto._internal({
    required this.failureString,
  });

  final String failureString;

  @override
  List<Object?> get props {
    return [
      failureString,
    ];
  }

  factory _WebPaymentMethodFailureDto.fromString(String failureString) {
    return _WebPaymentMethodFailureDto._internal(
      failureString: failureString,
    );
  }

  factory _WebPaymentMethodFailureDto.fromEntity(WebPaymentMethodFailure failure) {
    late final String failureString;

    if (failure == WebPaymentMethodFailure.cardExpired) {
      failureString = _kWebPaymentFailureCardExpiredValue;
    } else if (failure == WebPaymentMethodFailure.cardUnavailable) {
      failureString = _kWebPaymentFailureCardUnavailableValue;
    }

    return _WebPaymentMethodFailureDto._internal(
      failureString: failureString,
    );
  }

  @override
  String toString() {
    return failureString;
  }

  WebPaymentMethodFailure toEntity() {
    if (failureString == _kWebPaymentFailureCardExpiredValue) {
      return WebPaymentMethodFailure.cardExpired;
    }

    if (failureString == _kWebPaymentFailureCardUnavailableValue) {
      return WebPaymentMethodFailure.cardUnavailable;
    }

    throw UnimplementedError();
  }
}
